﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manage_ImportData : System.Web.UI.Page, IAccess
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentAccount.CheckSessionTimeOut(this);
    }
    #region IAccess Members

    IList<EnumAccess> IAccess.AccessList
    {
        get
        {
            var list = new List<EnumAccess>();
            list.Add(EnumAccess.Manage);
            return list;
        }

    }

    #endregion
    protected void btnClearBargain_Click(object sender, EventArgs e)
    {
        if (BLL_Factory.IBLL_Manage.ClearBargainData() == 1)
        {
            HZ.Web.WebUtil.Alert("议价数据清空成功", this);
        }
        else
        {
            HZ.Web.WebUtil.Alert("议价数据清空失败", this);
        }


    }
    private void BindData()
    {
        gvbargin.DataSource = HZ.Data.DbHelperFactory.Create().ExecuteTable("SELECT TOP 20 * FROM TB_Bargain");
        gvbargin.DataBind();
    }

    protected void btnImortBargain_Click(object sender, EventArgs e)
    {
        if (fubargain.HasFile)
        {
            string folder = System.Environment.GetEnvironmentVariable("TEMP");
            string filenme = Guid.NewGuid().ToString() + ".xls";
            string fullpath = folder + "\\" + filenme;

            fubargain.SaveAs(fullpath);

            HZ.Data.OledbHelper oledb = new HZ.Data.OledbHelper(string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";", fullpath));

            var dt = oledb.ExecuteTable(string.Format("SELECT * FROM [{0}]", txtSheetName.Text + "$"));

            try
            {
                if (1 == BLL_Factory.IBLL_Manage.ImportBaragainData(dt))
                {
                    HZ.Web.WebUtil.Alert("已导入成功", this);
                    BindData();
                }
            }
            catch (Exception ee)
            {
                Util.Alert2(ee.Message, this);
            }

        }
        else
        {


            HZ.Web.WebUtil.Alert("请选择文件后再导入", this);
        }
    }

    protected void btnExportBargain_Click(object sender, EventArgs e)
    {
        HZ.Web.WebUtil.ExportToExcel(HZ.Data.DbHelperFactory.Create().ExecuteTable("SELECT * FROM  dbo.View_BargainPrice"), "bargain.xls");
    }
}
